{extend name="common/base"/}
<!-- 样式 -->
{block name="style"}
<style>
	html,
	body {
		height: calc(100% - 20px);
	}
</style>
{/block}
<!-- /样式 -->
<!-- 主体 -->
{block name="body"}
<div class="body-content" style="height: 100%">
	<div>
		<a class="layui-btn layui-btn-normal layui-btn-sm" href="/admin/nav/nav_info_add?nid={$nav_id}">+ 添加导航</a>
	</div>
	<div style="height: calc(100% - 30px);margin-top: 10px;">
		<table class="layui-hide" id="treeTable" lay-filter="treeTable"></table>
	</div>
</div>
<script type="text/html" id="target">
	<i class="layui-icon {{#  if(d.target == 1){ }}layui-icon-ok{{#  } else { }}layui-icon-close{{#  } }}"></i>
</script>
<script type="text/html" id="status">
	<i class="layui-icon {{#  if(d.status == 1){ }}layui-icon-ok{{#  } else { }}layui-icon-close{{#  } }}"></i>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	var nid = {$nav_id},
		editObj = null,
		ptable = null,
		treeGrid = null,
		tableId = 'treeTable',
		layer = null;

	function init(layui) {
		var table = layui.table;
		treeGrid = layui.treeGrid; //很重要
		layer = layui.layer;
		ptable = treeGrid.render({
			id: tableId,
			elem: '#' + tableId,
			idField: 'id',
			url: '/admin/nav/nav_info', //数据接口
			where: {
				id:nid
			},
			cellMinWidth: 100,
			treeId: 'id', //树形id字段名称
			treeUpId: 'pid', //树形父id字段名称
			treeShowName: 'title', //以树形式显示的字段
			cols: [
				[{
					field: 'sort',
					width: 80,
					title: '排序',
					align: 'center'
				}, {
					field: 'id',
					width: 80,
					title: 'ID号',
					align: 'center'
				}, {
					field: 'title',
					width: 220,
					title: '名称',
				}, {
					field: 'pid',
					title: '父级ID',
					width: 80,
					align: 'center'
				}, {
					field: 'src',
					title: '链接'
				},{
					field: 'target',
					title: '新窗口打开',
					toolbar: '#target',
					align: 'center',
					width: 100
				},{
					field: 'status',
					title: '状态',
					toolbar: '#status',
					align: 'center',
					width: 60
				}, {
					width: 180,
					title: '操作',
					align: 'center',
					templet: function (d) {
						var html = '';
						var addBtn =
							'<a class="layui-btn layui-btn-normal layui-btn-xs" href="/admin/nav/nav_info_add?nid={$nav_id}&pid=' + d.id +
							'">添加子导航</a><a class="layui-btn layui-btn-xs" href="/admin/nav/nav_info_add?nid={$nav_id}&id=' + d.id +
							'">编辑</a>';
						var delBtn = '<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
						return addBtn + delBtn;
					}
				}]
			],
			page: false
		});
		//删除
		treeGrid.on('tool(' + tableId + ')', function (obj) {
			if (obj.event === 'del') {
				layer.confirm('确定要删除吗?', {
					icon: 3,
					title: '提示'
				}, function (index) {
					$.ajax({
						url: "/admin/nav/nav_info_delete",
						type: 'post',
						data: {
							id: obj.data.id
						},
						success: function (e) {
							layer.msg(e.msg);
							if (e.code == 0) {
								obj.del();
							}
						}
					})
					layer.close(index);
				});
			}
		});
	}
</script>
{include file="common/layui" base='base' extend="['treeGrid']" callback="init" /}
{/block}
<!-- /脚本 -->